﻿using LcAudit.BPM.Core;
using LcAudit.BPM.Core.Bll;
using LcAudit.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using Omu.ValueInjecter;

namespace LcAudit.BPM.Admin.mobileSendInfo.ashx
{
    /// <summary>
    /// mobilehandler 的摘要说明
    /// </summary>
    public class mobilehandler : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            if (SysVisitor.Instance.IsGuest)
            {
                context.Response.Write(
                    new JsonMessage { Success = false, Data = "-99", Message = "登录已过期，请重新登录" }.ToString()
                    );
                context.Response.End();
            }

            var json = HttpContext.Current.Request["json"];
            var rpm = new RequestParamModel<LcAudit.BPM.Core.Model.mobileSendInfo>(context) { CurrentContext = context, Action = context.Request["action"] };
            if (!string.IsNullOrEmpty(json))
            {
                rpm = JSONhelper.ConvertToObject<RequestParamModel<LcAudit.BPM.Core.Model.mobileSendInfo>>(json);
                rpm.CurrentContext = context;
            }

            switch (rpm.Action)
            {
                case "add":
                    context.Response.Write(mobileSendInfoBll.Instance.Add(rpm.Entity));
                    break;
                case "edit":
                    LcAudit.BPM.Core.Model.mobileSendInfo u = new LcAudit.BPM.Core.Model.mobileSendInfo();
                    u.InjectFrom(rpm.Entity);                    
                    context.Response.Write(mobileSendInfoBll.Instance.Edit(u));
                    break;

                case "del":
                    var dconfig = PublicMethod.GetInt(rpm.KeyId);
                    string dmsg = mobileSendInfoBll.Instance.Delete(dconfig);
                    context.Response.Write(dmsg);
                    break;
                case "pic":
                    context.Response.BinaryWrite(mobileSendInfoBll.Instance.Getpic(PublicMethod.GetInt(HttpContext.Current.Request["KeyId"])));
                    break;
                default:
                    context.Response.Write(mobileSendInfoBll.Instance.GetJsonData(rpm.Pageindex, rpm.Pagesize, rpm.Filter, rpm.Sort, rpm.Order));
                    break;
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}